package com.example.time.handler;

import com.example.time.pojo.UnixTime;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

/**
 * @author linfeng
 * @date 2022/1/17 16:50
 */
public class TimeServerHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void channelActive(ChannelHandlerContext ctx) {
        System.out.println("和一个客户端建立连接");
        ChannelFuture f = ctx.writeAndFlush(new UnixTime(System.currentTimeMillis()));
        f.addListener(ChannelFutureListener.CLOSE);
    }
}
